package ui.activity.partner.presenter;


import com.google.gson.Gson;

import javax.inject.Inject;

import Bean.AllyBean;
import Bean.AllyParamBean;
import base.BaseBiz;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import ui.activity.partner.biz.PartnerBiz;
import ui.activity.partner.contract.PartnerContract;

/**
 * Created by chenjian on 19/3/11.
 */

public class PartnerPresenter implements PartnerContract.Presenter {

    PartnerContract.View view;
    PartnerBiz partnerBiz;


    @Inject
    public PartnerPresenter(PartnerContract.View view) {
        this.view = view;
    }


    @Override
    public void setBiz(BaseBiz biz) {
        partnerBiz = (PartnerBiz) biz;
    }


    @Override
    public void getPartnerList(boolean isRefresh, int customId, int type, int px, String keyWord) {
        view.loading(true);
        AllyParamBean orderParamBean = new AllyParamBean();
        orderParamBean.setCustomId(customId);
        orderParamBean.setKey(keyWord);
        orderParamBean.setPx(px);
        orderParamBean.setType(type);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), new Gson().toJson(orderParamBean));
        partnerBiz.getPartnerList(requestBody, new BaseBiz.Callback<AllyBean.DataBean>() {
            @Override
            public void onSuccess(AllyBean.DataBean info) {
                view.upDateUI(info);
                view.hasLoadMore(false);
                if (isRefresh) {
                    view.refreshComplete();
                } else {
                    view.loadMoreComplete();
                }
                view.loading(false);
            }

            @Override
            public void onFailure(AllyBean.DataBean info) {
                view.loading(false);
                if (isRefresh) {
                    view.refreshComplete();
                } else {
                    view.loadMoreComplete();
                }
            }
        });
    }
}
